﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySql.Data.MySqlClient;
using System.Data;
public partial class _Default : System.Web.UI.Page
{

    public static bool loginFlag = false;
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
      
       
       
    }
    protected void Button1_Click1(object sender, EventArgs e)
    {
        //string conn = @"Server=123.30.210.85;Database=ecithanh_dulieu;Port=3306;UserID=ecithanh_dulieu;Password=hoang123;charset=utf8";
        DatabaseHandler db = new DatabaseHandler();
        MySqlConnection con = new MySqlConnection(DatabaseHandler.strConnect);
        con.Open();

       
        MySqlDataAdapter ad = new MySqlDataAdapter("select * from tbl_users", con);
        DataSet ds = new DataSet();
        ad.Fill(ds, "tbl");


        Boolean check = false;
        Boolean ch = false;
        for (int i = 0; i < ds.Tables["tbl"].Rows.Count-1; i++)
        {
            DataRow dr;
            dr = ds.Tables["tbl"].Rows[i];
            if ((dr["Username"].ToString() == txtuser.Text) && (dr["Password"].ToString() == txtpass.Text))
            {
                check = true;
               
               
            }
            if ((dr["Username"].ToString() == txtuser.Text) && (dr["Role"].ToString() == "Admin"))
            {
                ch = true;


            }
        }
        if ((check == true) && (ch == true))
        {
            Variables.loginFlag=true;
            Variables.roleFlag=true;
            Response.Redirect("Index.aspx");

        }
        else
        {

            Label2.Text = "Kiểm tra lại username và mật khẩu !";

        }

       

    }
   
}